package com.bhs.sansong.ui.main;

import android.content.Intent;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.viewpager2.widget.ViewPager2;

import com.bhs.sansong.R;
import com.bhs.sansong.adapter.FragmentAdapter;
import com.bhs.sansong.base.BaseFragment;
import com.bhs.sansong.ui.order.OrderSearchActivity;
import com.bhs.sansong.ui.order.ReceivingNoteFragment;
import com.bhs.sansong.ui.order.ShipmentsOrderFragment;
import com.bhs.sansong.view.SelectedFont2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;

/**
 * 订单
 */
public class OrderGoodsFragment extends BaseFragment implements View.OnClickListener {

    private TabLayout mTabLayout;
    private ViewPager2 mViewPage;

    public static OrderGoodsFragment newInstance() {
        return new OrderGoodsFragment();
    }

    @Override
    public int initLayout() {
        return R.layout.fragment_order_goods;
    }

    @Override
    public void initView(View root) {

        mTabLayout = root.findViewById(R.id.tabLayout);
        root.findViewById(R.id.fl_search).setOnClickListener(this);
        mViewPage = root.findViewById(R.id.view_page);
        mTabLayout.setTabMode(TabLayout.MODE_AUTO);
        mTabLayout.addOnTabSelectedListener(new SelectedFont2(activity));
    }

    @Override
    public void initData() {
        ArrayList<BaseFragment> fragments = new ArrayList<>();
        //1 发货单 2收货单
        fragments.add(ShipmentsOrderFragment.newInstance());
        fragments.add(ReceivingNoteFragment.newInstance());

        //禁止滑动
        mViewPage.setUserInputEnabled(false);
        mViewPage.setOffscreenPageLimit(fragments.size());
        mViewPage.setAdapter(new FragmentAdapter(activity, fragments));
        new TabLayoutMediator(mTabLayout, mViewPage, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(position == 0 ? "发货单" : "收货单");
            }
        }).attach();
    }

    @Override
    public void onClick(View view) {
        startActivity(new Intent(getContext(), OrderSearchActivity.class));
    }
}